package edu.dali.enterprise_test.service.menu.impl;

import com.github.pagehelper.Page;
import edu.dali.enterprise_test.dao.mapper.menu.MenuMapper;
import edu.dali.enterprise_test.model.Pager;
import edu.dali.enterprise_test.model.vo.Dto;
import edu.dali.enterprise_test.service.menu.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;
    @Override
    public Pager<Dto> getData(Dto params) {
        Pager p = new Pager();
        p.setCode(0);
        p.setMsg("");
        List<Dto> data = menuMapper.getData(params);
        int count = (int)((Page) data).getTotal();
        p.setData(data);
        p.setCount(count);
        return p;
    }

    @Override
    public Dto getDataById(String id) {
        return menuMapper.getDataById(id);
    }

    @Override
    public void addDish(Dto dto) {
        menuMapper.addDish(dto);
    }
    @Override
    public void update(Dto dto) {
        menuMapper.updateDish(dto);
    }
    @Override
    public void delete(Dto dto) {
        menuMapper.deleteDish(dto);
    }
}
